const mongoose = require("mongoose");

const QuoteSchema = new mongoose.Schema({
  quote: {
    type: String,
    required: true, // 必填项，存储名言内容
    unique: true,
  },
  author: {
    type: String,
    required: true, // 必填项，名言的作者
  },
});

// JSON 转换时格式化输出
QuoteSchema.set("toJSON", {
  transform(doc, ret) {
    ret.id = ret._id;
    delete ret._id;
    delete ret.__v;
    return ret;
  },
});

module.exports = mongoose.model("Quote", QuoteSchema);
